﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using HZ.MBSM.BLL;
using Grove.ORM;
using HZ.MBSM.Model;
using HZ.MBSM.DBUtility;
using System.Drawing;
public partial class Company_GoodsListJB : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        if (HZ.MBSM.BLL.Login.CheckAssert(this.UseAccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (_Account != null)
            {
                if (!IsPostBack)
                {
                    List_memo3.SelectedIndex = 4;
                }
 
                showGridView();
               
            }

        }
    }

    public void showGridView()
    {

        string strConditions = fctConditions();
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "Goods,Product";                                               //要查询的表明
        dbPage.Key = "goodsid";                                               //表的主键    
        dbPage.Where = strConditions;                                           //查询条件    
        dbPage.SelectField = "case when isnull(isdaishuye,0)>0  then goodsOther_bc else '' end as 包装材质,goods.productid,goodsid,productname_gjsp,Outlookc_gjsp,Medicinemodel_gjsp,unit_gjsp,factor,NoPass,shenhetime,case CheckStatus when '1' then '审核通过' when '2' then '审核未通过' when '3' then '纸质材料一致' else '未审核' end as CheckStatus, CASE QualityLevels " + ConfigurationManager.AppSettings["QualityLevels"].ToString() + " END AS QualityLevels ";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "productname_gjsp,Medicinemodel_gjsp,Outlookc_gjsp,goodsid";                  //排序字段
        System.Data.IDataReader dr = dbPage.ExecuteReader();
        GridView1.DataSource = dr;
        GridView1.DataBind();
        dr.Close();
        //dr.Dispose();
        dbPage.Db.Close();
        db.Close();
        //08.18
        dr = null;
        db = null;

        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }

    public string fctConditions()
    {
        Int64 Account_tjr;
        HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];

        string _strWhere = "";
        if (_Account != null)
        {
            Account_tjr = _Account.AccountId;

            _strWhere = @"and Goods.ProductId=Product.ProductId and  Accountid_tjr=" + Account_tjr + " ";

            //药品通用名或拼音码

            string _strProductName = SysFun.ToTrim(txtProductName.Text);
            if (_strProductName != "")
            {
                _strWhere += "and  (productname_gjsp like '%" + _strProductName + "%' ) ";
            }
            //审核状态
            if (List_memo3.SelectedValue != "4")
            {
                _strWhere += "and isnull(goods.CheckStatus,0)='" + List_memo3.SelectedValue + "' ";
            }

            //txtMedicinemodel
            //剂型
            string _strMedicinemodel = SysFun.ToTrim(txtMedicinemodel.Text);
            if (_strMedicinemodel != "")
            {
                _strWhere += "and  Medicinemodel_gjsp like '%" + _strMedicinemodel + "%' ";
            }

            //规格
            string _strOutlookc = SysFun.ToTrim(txtOutlookc.Text);
            if (_strOutlookc != "")
            {
                _strWhere += " and Outlookc_gjsp like '%" + _strOutlookc + "%'";
            }
            ////品目号 采用productid作为品目号显示在商品列表中  

            string _strProductid = SysFun.ToTrim(txtproductid.Text);
            if (_strProductid != "")
            {
                _strWhere += " and Product.Productid = '" + _strProductid + "'";
            }

            //流水号

            string _strGoodsId = SysFun.ToTrim(txtGoodsId.Text);
            if (_strGoodsId != "")
            {
                _strWhere += " And goodsid =" + _strGoodsId + " ";
            }


 
        }
        if (_strWhere != "")
        {
            _strWhere = "  " + _strWhere.Remove(0, 3);
        }

        return _strWhere;
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (e.Row.Cells[7].Text == "审核未通过")//审核状态
            {
                e.Row.BackColor = Color.Yellow;
            }
        }



    }
 

    #region IPageDescribe 成员


    public string Describe
    {
        get { return ""; }
    }
    public string Name
    {
        get { return "本企业商品信息"; }
    }
    public string ParentName
    {
        get { return "商品维护"; }
    }

    public System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> UseAccountType
    {
        get
        {
            System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumComapanyRG);
            _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCompany);

            return _AccountType;
        }
    }

    #endregion



    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {

        if (e.CommandName == "未审核")
        {
            HZ.MBSM.BLL.Goods bllgoods = new HZ.MBSM.BLL.Goods();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            if (bllgoods.GoodsJBByCompanyDelete(Convert.ToInt32(e.CommandArgument),_Account.AccountId.ToString()))
            {
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "删除", "goodsid", "bllgoods.GoodsByCompanyDelete(goodsid)" + e.CommandArgument, "../Company/GoodsList.aspx");

                showGridView();
                Response.Write("<script>alert('删除成功！！！');</script>");

            }
            else
            {
                Response.Write("<script>alert('发生异常！！！');</script>");
            }
        }
        else if (e.CommandName == "审核通过")
        {
            Response.Write("<script>alert('审核通过品种不让删除！！！');</script>");
        }
        else if (e.CommandName == "纸质材料一致")
        {
            Response.Write("<script>alert('纸质材料一致品种不让删除！！！');</script>");
        }
        else if (e.CommandName == "审核未通过")
        {
            Response.Write("<script>alert('审核未通过品种不让删除！！！');</script>");
        }
    }
     
}
